package com.music.controller;

import com.github.pagehelper.PageInfo;
import com.music.mapper.SingleSongMapper;
import com.music.pojo.SingleSong;
import com.music.pojo.UserInfo;
import com.music.service.SingleSongService;
import com.music.service.UserBasedCollaborativeFiltering;
import com.music.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
public class CollaborativeFilteringContriller {
    @Autowired
    private UserBasedCollaborativeFiltering userBasedCollaborativeFiltering;
    @Autowired
    private SingleSongService singleSongService;
    @Autowired
    private UserService userService;
    @RequestMapping("recommend")
    @ResponseBody
    public PageInfo<SingleSong> getRecommendSingleSongs(HttpServletRequest request,Integer pageNum){
        UserInfo userInfo = (UserInfo) request.getSession().getAttribute("userInfo");
        List<UserInfo> all = userService.find_all();
        Map<Integer, Map<Integer, Integer>> userSingleSongInfo = singleSongService.findUser_singleSongInfo(all);

        PageInfo<SingleSong> recommendMusicForUser = userBasedCollaborativeFiltering.recommendMusicForUser(userSingleSongInfo, userInfo.getUid(), 20,pageNum);
        return recommendMusicForUser;
    }
}
